/*
 *  Copyright (C) 2009  Peter Kist & Jan Ripke
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include "ManagerFactory.h"

#include <stdexcept>

#include <gfx/ogre/Manager.h>
#include <input/OIS/Manager.h>
#include <logic/gamestate/Manager.h>

namespace galaxy {

    ManagerFactory * ManagerFactory::m_Singleton = new ManagerFactory ();

    ManagerFactory::ManagerFactory(void)
    {
    }

    ManagerFactory::~ManagerFactory(void)
    {
    }

    ManagerFactory::ManagerPtr& ManagerFactory::getManager(mediator::Category category) {
        ManagerFactory& factory = ManagerFactory::singleton ();
        ManagerPtr& manager = factory.m_Managers[(int)category];
        if (! manager) {
            switch (category) {
                case mediator::CATEGORY_GFX: 
                    {
                        boost::shared_ptr<gfx::ogre3d::Manager>
                            gfxptr((gfx::ogre3d::Manager *) ManagerFactory::createGfxManager());
                        manager = gfxptr;
                        break;
                    }
                case mediator::CATEGORY_INPUT: 
                    {
                        boost::shared_ptr<input::ois_input::Manager> 
                            inputptr((input::ois_input::Manager *)ManagerFactory::createInputManager());
                        manager = inputptr;
                        break;
                    }
                case mediator::CATEGORY_LOGIC: 
                    {
                        boost::shared_ptr<logic::gamestate::Manager> 
                            logicptr((logic::gamestate::Manager *)ManagerFactory::createLogicManager());
                        manager = logicptr;
                        break;
                    }
            }
        }

        return manager;
    }

    ManagerFactory::ManagerMap& ManagerFactory::getManagerMap () {
        ManagerFactory& factory = singleton();
        return factory.m_Managers;
    }

    ModuleManager * ManagerFactory::createGfxManager () {
        return new gfx::ogre3d::Manager ();
    }

    ModuleManager * ManagerFactory::createInputManager () {
        return new input::ois_input::Manager ();
    }

    ModuleManager * ManagerFactory::createLogicManager () {
        return new logic::gamestate::Manager ();
    }


} // namespace galaxy
